var goroam = {};
goroam.array = {};
goroam.browser = {};
goroam.controls = {};
goroam.dhtml = {};
goroam.enm = {};
goroam.enm.browsers = { chrome: 'chrome', ie: 'ie', mozilla: 'mozilla', opera: 'opera', other: 'other', safari: 'safari' };
goroam.enm.icons = { pushpin: { blue: 'blue_pushpin', green: 'green_pushpin', orange: 'orange_pushpin', red: 'red_pushpin' }, goroam: 'goroam' };
goroam.event = {};
goroam.http = {};
goroam.math = {};
goroam.settings = {};
goroam.string = {};
goroam.system = {};
goroam.google = {};
goroam.google.maps = {};

// Load settings.
function QSObject(querystring){
  var arrResult = {};
  //Create regular expression object to retrieve the qs part 
  var qsReg = new RegExp("[?][^#]*","i"); 
  hRef = unescape(querystring); 
  var qsMatch = hRef.match(qsReg); 

  //removes the question mark from the url 
  qsMatch = new String(qsMatch); 
  qsMatch = qsMatch.substr(1, qsMatch.length -1); 

  //split it up 
  var rootArr = qsMatch.split("&"); 
  for(i=0;i<rootArr.length;i++) {
    var tempArr = rootArr[i].split("="); 
    if(tempArr.length==2){ 
      tempArr[0] = unescape(tempArr[0]).toLowerCase(); 
      tempArr[1] = unescape(tempArr[1]); 
      arrResult[tempArr[0]]= tempArr[1]; 
    } 
  }
  return arrResult;
} 

var arrScriptSrc = document.getElementsByTagName("script");
var scriptSrc = '';
for (var i = 0; i < arrScriptSrc.length; i++) {
  if (arrScriptSrc[i].src.match(/\/scripts\/goroam\.api\.js/i) || arrScriptSrc[i].src.match(/geo\.(go-roam\.com|goro\.am)\/api.*\.js/i)) {
    scriptSrc = arrScriptSrc[i].src;
    break;
  }
}
goroam.settings = new QSObject(scriptSrc);
if (goroam.settings.settings) {
  var arrSettings = goroam.settings.settings.split('/');
  for (i=0;i<arrSettings.length;i++) {
    var tempArr = arrSettings[i].split("-"); 
    if(tempArr.length>1){ 
      tempArr[0] = unescape(tempArr[0]).toLowerCase(); 
      tempArr[1] = unescape(tempArr[1]); 
      goroam.settings[tempArr[0]]= tempArr[1]; 
    } 
  }
}
if (!goroam.settings.v) {
  goroam.settings.v = '0.2.compressed';
} else {
  goroam.settings.v = goroam.settings.v.toLowerCase().replace('-', '.');
  switch (goroam.settings.v) {
    case '0.1.compressed', '0.1', '0.2.compressed', '0.2':
      // do nothing
      break;
    default:
      goroam.settings.v = '0.2.compressed';
      break;
  }
}
if (!goroam.settings.map) goroam.settings.map = 'map';
if (!goroam.settings.lat) goroam.settings.lat = 39;
if (!goroam.settings.lng) goroam.settings.lng = -98;
if (!goroam.settings.zoom) goroam.settings.zoom = 4;
if (!goroam.settings.controls) goroam.settings.controls = 'all';
if (!goroam.settings.position) {
  goroam.settings.position = 'out_nw';
} else {
  goroam.settings.position = goroam.settings.position.toLowerCase();
  switch (goroam.settings.position) {
    case 'ne', 'se', 'sw', 'nw', 'out_ne', 'out_se', 'out_sw', 'out_nw':
      // do nothing
      break;
    default:
      goroam.settings.position = 'out_nw';
      break;
  }
}
if (!goroam.settings.line_color) goroam.settings.line_color = '#0000ff';
if (!goroam.settings.line_width) goroam.settings.line_width = 5;
if (!goroam.settings.line_opacity) goroam.settings.line_opacity = 0.75;
if (!goroam.settings.line_on_roads) {
  goroam.settings.line_on_roads = 'no';
} else {
  goroam.settings.line_on_roads = goroam.settings.line_on_roads.toLowerCase();
  switch (goroam.settings.line_on_roads) {
    case 'no', 'yes', 'driving', 'walking':
      // do nothing
      break;
    default:
      goroam.settings.line_on_roads = 'no';
      break;
  }
}
if (!goroam.settings.marker_icon) goroam.settings.marker_icon = '';
if (!goroam.settings.root_url) goroam.settings.root_url = 'https://goroam.googlecode.com/svn/trunk';
document.write('<link rel="stylesheet" type="text/css" href="' + goroam.settings.root_url + '/css/default.css" />');
if (goroam.settings.gmaps_key) document.write('<scri' + 'pt src="http://www.google.com/jsapi?key=' + goroam.settings.gmaps_key + '" type="text/javascript"></scri' + 'pt>');
document.write('<scri' + 'pt src="' + goroam.settings.root_url + '/scripts/goroam.api.' + goroam.settings.v + '.js" type="text/javascript"></scri' + 'pt>');

